package com.hans.myscanner.Scanner.Activity;

import android.app.Dialog;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import com.hans.dialog.ChangeColorWindow;
import com.hans.dialog.ShareDialog;
import com.hans.dialog.TransBgDialog;
import com.hans.myscanner.R;

/**
 * Created by Administrator on 2016/7/9.
 */
public class QRMakeActivity extends AppCompatActivity {
    private View changeColorBtn,shareBtn,qrBgLayout;
    private ImageView qrImg;
    private ChangeColorWindow changeColorWindow;
    private Dialog shareDialog;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_qr_make);
        findView();
        initView();
    }

    private void findView() {
        qrBgLayout=findViewById(R.id.qr_bg);
        changeColorBtn=findViewById(R.id.change_color_btn);
        shareBtn=findViewById(R.id.share_btn);
        qrImg= (ImageView) findViewById(R.id.qr_img);
        changeColorWindow=new ChangeColorWindow(QRMakeActivity.this);
    }
    private void initView() {
        changeColorBtn.setOnClickListener(onClickListener);
        shareBtn.setOnClickListener(onClickListener);
        changeColorWindow.setOnColorChangedListener(new ChangeColorWindow.OnColorChangedListener() {
            @Override
            public void onBgColorChanged(int color) {
                qrBgLayout.setBackgroundColor(color);
            }

            @Override
            public void onFgColorChanged(int color) {
                Toast.makeText(QRMakeActivity.this,"前景改变",Toast.LENGTH_SHORT);
            }
        });
    }

    protected  void initDialog(){
        shareDialog=new TransBgDialog(QRMakeActivity.this,R.layout.dialog_share);
        shareDialog.findViewById(R.id.title_tv).setOnClickListener(onClickListener);
        shareDialog.findViewById(R.id.message_gv).setOnClickListener(onClickListener);
        shareDialog.findViewById(R.id.close_btn).setOnClickListener(onClickListener);

    }

//    protected  void initDialog(){
//        makeContactDialog=new TransBgDialog(MakeSubActivity.this,R.layout.make_contact_dialog);
//        makeContactDialog.findViewById(R.id.choose_contact_btn).setOnClickListener(onClickListener);
//        makeContactDialog.findViewById(R.id.new_contact_btn).setOnClickListener(onClickListener);
//        makeContactDialog.findViewById(R.id.close_btn).setOnClickListener(onClickListener);
//
//    }


    private void onDestory(){
        super.onDestroy();
        if(changeColorWindow!=null && changeColorWindow.isShowing()){
            changeColorWindow.dismiss();
            changeColorWindow=null;
        }
    }

    private View.OnClickListener onClickListener=new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()){
                case R.id.change_color_btn:
                    changeColorWindow.show(changeColorBtn);
                    break;
                case R.id.share_btn:
                    shareDialog.show();
                    break;
                case R.id.title_tv:
                    shareDialog.setTitle("分享");
                    break;
                case R.id.message_gv:

                    break;
                case R.id.close_btn:
                    shareDialog.dismiss();
                    break;
            }
        }

    };
}
